#pragma once

class SoundTransducer
{
public:
	SoundTransducer()
	{
		LastIn = 0;
		Avg = 0;
		LastSample = 0;
	};

	~SoundTransducer()
	{
	};

	double Process(double In)
	{
		const double Amp = 4000000.f;
		In *= Amp;

		double Sample = (Avg - In);

		if (Sample < -32767)
			Sample = -32767;

		if (Sample > 32767)
			Sample = 32767;

		Avg = Avg * 0.5f + In * 0.5f;

		Sample = Sample * 0.5 + LastSample * 0.5;
		LastSample = Sample;

		return Sample;
	};

private:
	double LastSample;
	double LastIn;
	double Avg;
};


/*

class SoundTransducer
{
public:
	SoundTransducer()
	{ 
		LastIn = 0.f; 
		Avg = 0.f;
	};

	~SoundTransducer()
	{
	};
	
	double Process(double In)
	{
		const double Amp = 3000000.f;

		Avg = Avg * 0.8 + LastIn * 0.2;
		
		const double Delta = (Avg - In);
		
		//const double Delta = LastDelta * 0.7 + (Avg - In) * 0.3;

		//LastDelta = Delta;

		//LastIn4 = LastIn3;
		//LastIn3 = LastIn2;
		//LastIn2 = LastIn;
		LastIn = In;

		double Sample = Delta * Amp;

		if (Sample > 32768.f)
			Sample = 32768.f;

		if (Sample < -32768.f)
			Sample = -32768.f;

		return Sample;
	};

private:
	double LastIn4;
	double LastIn3;
	double LastDelta;

	double LastIn2;
	double LastIn;
	double Avg;
};




/*float Process(float In)
{
	const float Amp = 10000000.f;

	float Delta = (LastIn - In) * Amp;

	LastIn2 = LastIn;
	LastIn = In;

	const float Sample = Delta - Avg;

	Avg = Avg * 0.7f + Delta * 0.3f;


	return Sample;
};*/